package com.wonderful.mall.order.vo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

//订单确认页需要的数据
@ToString
public class OrderConfirmVo {
    //收货地址
    @Setter
    @Getter
    private List<MemberAddressVo> address;
    //所有选中的购物项
    @Setter
    @Getter
    List<OrderItemVo> items;

    @Setter
    @Getter
    Map<Long,Boolean> stocks;

    public Integer getCount(){
        Integer i = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    //优惠券 积分
    @Setter
    @Getter
    Integer integration;

    //订单总额
    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal(0);
        if (items != null) {
            for (OrderItemVo item : items) {
                sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount())));
            }
        }
        return sum;
    }

    //应付
    public BigDecimal getPayPrice(){
        return getTotal();
    }

    //防重令牌
    @Getter @Setter
    String orderToken;
}
